package org.usmile.algorithms.huawei.acm;

import java.util.*;

// https://blog.csdn.net/amos_cloud/article/details/129254021
public class _字母组合 {
    private static char[] nums;
    private static Set<Character> includeSet;
    private static final List<String> result = new ArrayList<>();
    private static final Map<Character, String> map = new HashMap<>();

    static {
        map.put('0', "abc");
        map.put('1', "def");
        map.put('2', "ghi");
        map.put('3', "jkl");
        map.put('4', "mno");
        map.put('5', "pqr");
        map.put('6', "st");
        map.put('7', "uv");
        map.put('8', "wx");
        map.put('9', "yz");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        nums = sc.nextLine().toCharArray();
        char[] notContains = sc.nextLine().toCharArray();
        includeSet = new HashSet<>();
        for (char c : notContains) {
            includeSet.add(c);
        }
        dfs(-1, "", 0);
        StringBuilder sb = new StringBuilder();
        for (String str : result) {
            sb.append(str).append(",");
        }
        System.out.println(sb.toString());
    }

    private static void dfs(int start, String path, int includeCount) {
        if (includeCount >= includeSet.size()) {
            return;
        }
        if (path.length() == nums.length) {
            result.add(path);

            return;
        }

        for (int i = start + 1; i < nums.length; i++) {
            char[] chars = map.get(nums[i]).toCharArray();
            for (char curr : chars) {
                boolean isInclude = includeSet.contains(curr);
                dfs(i, path + curr, isInclude ? includeCount + 1 : includeCount);
            }
        }
    }
}
